package net.scdx.hotel.service.impl;
import net.scdx.hotel.dto.OrderExecution;
import net.scdx.hotel.dto.UserExecution;
import net.scdx.hotel.entity.Order;
import net.scdx.hotel.mapper.OrderMapper;
import net.scdx.hotel.service.OrderService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class OrderServiceImpl implements OrderService{
    @Autowired
    private OrderMapper orderMapper;
    @Override
    public List<Order> orderInfo(Integer userId) throws Exception{
        List<Order>  orders= orderMapper.selectByForeignKey(userId);
        return orders;
    }
    @Override
    public UserExecution addOrder(Order order) throws Exception{
        boolean success = true;
        String msg = "";

        if (order.getRoomId()== null ) {   //进一步修改
            msg = "insert error";
            success = false;
        }
        else{
            int effectedNum = orderMapper.insert(order);
            if (effectedNum <= 0){
                success = false;
                msg = "insert into database failure";
            }
        }

        return new UserExecution(success, msg,null);
    }

    @Override
    public boolean modifyOrderstatus(Integer orderId) throws Exception{
        int effectedNum = orderMapper.updateStatusByPrimaryKey(orderId);
        if (effectedNum > 0)
            return true;
        return false;
    }
}
